package com.google.android.material.transformation;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.CallSuper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout.a;
import androidx.core.view.ViewCompat;
import com.google.android.material.circularreveal.CircularRevealHelper;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.List;
import o.aqr;
import o.aqs;
import o.aqt;
import o.aqu.j;
import o.aqv;
import o.aqw;
import o.aqx;
import o.aqz;
import o.are;
import o.arm;
import o.arm.d;
import o.aro;
import o.asf;

public abstract class FabTransformationBehavior extends ExpandableTransformationBehavior {
    private final RectF ˋ;
    private final RectF ˎ;
    private final int[] ˏ;
    private final Rect ॱ;

    protected static class c {
        public are ˊ;
        public aqz ˋ;

        protected c() {
        }
    }

    protected abstract c ˊ(Context context, boolean z);

    public FabTransformationBehavior() {
        this.ॱ = new Rect();
        this.ˎ = new RectF();
        this.ˋ = new RectF();
        this.ˏ = new int[2];
    }

    public FabTransformationBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ॱ = new Rect();
        this.ˎ = new RectF();
        this.ˋ = new RectF();
        this.ˏ = new int[2];
    }

    @CallSuper
    public boolean ॱ(CoordinatorLayout coordinatorLayout, View view, View view2) {
        if (view.getVisibility() == 8) {
            throw new IllegalStateException("This behavior cannot be attached to a GONE view. Set the view to INVISIBLE instead.");
        } else if (!(view2 instanceof FloatingActionButton)) {
            return false;
        } else {
            int ʻ = ((FloatingActionButton) view2).ʻ();
            if (ʻ == 0 || ʻ == view.getId()) {
                return true;
            }
            return false;
        }
    }

    @CallSuper
    public void ˊ(@NonNull a aVar) {
        if (aVar.ʻ == 0) {
            aVar.ʻ = 80;
        }
    }

    @NonNull
    protected AnimatorSet ˎ(View view, View view2, boolean z, boolean z2) {
        c ˊ = ˊ(view2.getContext(), z);
        List arrayList = new ArrayList();
        List arrayList2 = new ArrayList();
        if (VERSION.SDK_INT >= 21) {
            ॱ(view, view2, z, z2, ˊ, arrayList, arrayList2);
        }
        RectF rectF = this.ˎ;
        ˎ(view, view2, z, z2, ˊ, arrayList, arrayList2, rectF);
        float width = rectF.width();
        float height = rectF.height();
        ˏ(view, view2, z, z2, ˊ, arrayList, arrayList2);
        ˎ(view, view2, z, z2, ˊ, width, height, arrayList, arrayList2);
        ˋ(view, view2, z, z2, ˊ, arrayList, arrayList2);
        ˎ(view, view2, z, z2, ˊ, arrayList, arrayList2);
        AnimatorSet animatorSet = new AnimatorSet();
        aqs.ˏ(animatorSet, arrayList);
        final boolean z3 = z;
        final View view3 = view2;
        final View view4 = view;
        animatorSet.addListener(new AnimatorListenerAdapter(this) {
            final /* synthetic */ FabTransformationBehavior ˎ;

            public void onAnimationStart(Animator animator) {
                if (z3) {
                    view3.setVisibility(0);
                    view4.setAlpha(0.0f);
                    view4.setVisibility(4);
                }
            }

            public void onAnimationEnd(Animator animator) {
                if (!z3) {
                    view3.setVisibility(4);
                    view4.setAlpha(1.0f);
                    view4.setVisibility(0);
                }
            }
        });
        int size = arrayList2.size();
        for (int i = 0; i < size; i++) {
            animatorSet.addListener((AnimatorListener) arrayList2.get(i));
        }
        return animatorSet;
    }

    @TargetApi(21)
    private void ॱ(View view, View view2, boolean z, boolean z2, c cVar, List<Animator> list, List<AnimatorListener> list2) {
        Animator ofFloat;
        float ˊॱ = ViewCompat.ˊॱ(view2) - ViewCompat.ˊॱ(view);
        if (z) {
            if (!z2) {
                view2.setTranslationZ(-ˊॱ);
            }
            ofFloat = ObjectAnimator.ofFloat(view2, View.TRANSLATION_Z, new float[]{0.0f});
        } else {
            ofFloat = ObjectAnimator.ofFloat(view2, View.TRANSLATION_Z, new float[]{-ˊॱ});
        }
        cVar.ˋ.ˏ("elevation").ˊ(ofFloat);
        list.add(ofFloat);
    }

    private void ˎ(View view, View view2, boolean z, boolean z2, c cVar, List<Animator> list, List<AnimatorListener> list2, RectF rectF) {
        aqw ˏ;
        aqw ˏ2;
        Animator animator;
        Animator animator2;
        float ˎ = ˎ(view, view2, cVar.ˊ);
        float ॱ = ॱ(view, view2, cVar.ˊ);
        if (ˎ == 0.0f || ॱ == 0.0f) {
            ˏ = cVar.ˋ.ˏ("translationXLinear");
            ˏ2 = cVar.ˋ.ˏ("translationYLinear");
        } else if ((!z || ॱ >= 0.0f) && (z || ॱ <= 0.0f)) {
            ˏ = cVar.ˋ.ˏ("translationXCurveDownwards");
            ˏ2 = cVar.ˋ.ˏ("translationYCurveDownwards");
        } else {
            ˏ = cVar.ˋ.ˏ("translationXCurveUpwards");
            ˏ2 = cVar.ˋ.ˏ("translationYCurveUpwards");
        }
        if (z) {
            if (!z2) {
                view2.setTranslationX(-ˎ);
                view2.setTranslationY(-ॱ);
            }
            Animator ofFloat = ObjectAnimator.ofFloat(view2, View.TRANSLATION_X, new float[]{0.0f});
            Animator ofFloat2 = ObjectAnimator.ofFloat(view2, View.TRANSLATION_Y, new float[]{0.0f});
            ˎ(view2, cVar, ˏ, ˏ2, -ˎ, -ॱ, 0.0f, 0.0f, rectF);
            animator = ofFloat2;
            animator2 = ofFloat;
        } else {
            animator2 = ObjectAnimator.ofFloat(view2, View.TRANSLATION_X, new float[]{-ˎ});
            animator = ObjectAnimator.ofFloat(view2, View.TRANSLATION_Y, new float[]{-ॱ});
        }
        ˏ.ˊ(animator2);
        ˏ2.ˊ(animator);
        list.add(animator2);
        list.add(animator);
    }

    private void ˏ(View view, final View view2, boolean z, boolean z2, c cVar, List<Animator> list, List<AnimatorListener> list2) {
        if ((view2 instanceof arm) && (view instanceof ImageView)) {
            final arm o_arm = (arm) view2;
            final Drawable drawable = ((ImageView) view).getDrawable();
            if (drawable != null) {
                Animator ofInt;
                drawable.mutate();
                if (z) {
                    if (!z2) {
                        drawable.setAlpha(255);
                    }
                    ofInt = ObjectAnimator.ofInt(drawable, aqx.ˏ, new int[]{0});
                } else {
                    ofInt = ObjectAnimator.ofInt(drawable, aqx.ˏ, new int[]{255});
                }
                ofInt.addUpdateListener(new AnimatorUpdateListener(this) {
                    final /* synthetic */ FabTransformationBehavior ˋ;

                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        view2.invalidate();
                    }
                });
                cVar.ˋ.ˏ("iconFade").ˊ(ofInt);
                list.add(ofInt);
                list2.add(new AnimatorListenerAdapter(this) {
                    final /* synthetic */ FabTransformationBehavior ˏ;

                    public void onAnimationStart(Animator animator) {
                        o_arm.setCircularRevealOverlayDrawable(drawable);
                    }

                    public void onAnimationEnd(Animator animator) {
                        o_arm.setCircularRevealOverlayDrawable(null);
                    }
                });
            }
        }
    }

    private void ˎ(View view, View view2, boolean z, boolean z2, c cVar, float f, float f2, List<Animator> list, List<AnimatorListener> list2) {
        if (view2 instanceof arm) {
            Animator animator;
            arm o_arm = (arm) view2;
            float ˋ = ˋ(view, view2, cVar.ˊ);
            float ˊ = ˊ(view, view2, cVar.ˊ);
            ((FloatingActionButton) view).ॱ(this.ॱ);
            float width = ((float) this.ॱ.width()) / 2.0f;
            aqw ˏ = cVar.ˋ.ˏ("expansion");
            if (z) {
                if (!z2) {
                    o_arm.setRevealInfo(new d(ˋ, ˊ, width));
                }
                float f3 = z2 ? o_arm.k_().ˎ : width;
                Animator ˎ = aro.ˎ(o_arm, ˋ, ˊ, asf.ˎ(ˋ, ˊ, 0.0f, 0.0f, f, f2));
                final arm o_arm2 = o_arm;
                ˎ.addListener(new AnimatorListenerAdapter(this) {
                    final /* synthetic */ FabTransformationBehavior ˏ;

                    public void onAnimationEnd(Animator animator) {
                        d k_ = o_arm2.k_();
                        k_.ˎ = Float.MAX_VALUE;
                        o_arm2.setRevealInfo(k_);
                    }
                });
                int i = (int) ˊ;
                ˏ(view2, ˏ.ˋ(), (int) ˋ, i, f3, list);
                animator = ˎ;
            } else {
                float f4 = o_arm.k_().ˎ;
                Animator ˎ2 = aro.ˎ(o_arm, ˋ, ˊ, width);
                ˏ(view2, ˏ.ˋ(), (int) ˋ, (int) ˊ, f4, list);
                int i2 = (int) ˊ;
                ˎ(view2, ˏ.ˋ(), ˏ.ˎ(), cVar.ˋ.ˎ(), (int) ˋ, i2, width, (List) list);
                animator = ˎ2;
            }
            ˏ.ˊ(animator);
            list.add(animator);
            list2.add(aro.ˏ(o_arm));
        }
    }

    private void ˋ(View view, View view2, boolean z, boolean z2, c cVar, List<Animator> list, List<AnimatorListener> list2) {
        if (view2 instanceof arm) {
            Animator ofInt;
            arm o_arm = (arm) view2;
            int ˊ = ˊ(view);
            int i = 16777215 & ˊ;
            if (z) {
                if (!z2) {
                    o_arm.setCircularRevealScrimColor(ˊ);
                }
                ofInt = ObjectAnimator.ofInt(o_arm, arm.a.ˎ, new int[]{i});
            } else {
                ofInt = ObjectAnimator.ofInt(o_arm, arm.a.ˎ, new int[]{ˊ});
            }
            ofInt.setEvaluator(aqt.ॱ());
            cVar.ˋ.ˏ("color").ˊ(ofInt);
            list.add(ofInt);
        }
    }

    private void ˎ(View view, View view2, boolean z, boolean z2, c cVar, List<Animator> list, List<AnimatorListener> list2) {
        if (!(view2 instanceof ViewGroup)) {
            return;
        }
        if (!(view2 instanceof arm) || CircularRevealHelper.ˊ != 0) {
            ViewGroup ˎ = ˎ(view2);
            if (ˎ != null) {
                Animator ofFloat;
                if (z) {
                    if (!z2) {
                        aqr.ˊ.set(ˎ, Float.valueOf(0.0f));
                    }
                    ofFloat = ObjectAnimator.ofFloat(ˎ, aqr.ˊ, new float[]{1.0f});
                } else {
                    ofFloat = ObjectAnimator.ofFloat(ˎ, aqr.ˊ, new float[]{0.0f});
                }
                cVar.ˋ.ˏ("contentFade").ˊ(ofFloat);
                list.add(ofFloat);
            }
        }
    }

    private float ˎ(View view, View view2, are o_are) {
        RectF rectF = this.ˎ;
        RectF rectF2 = this.ˋ;
        ˎ(view, rectF);
        ˎ(view2, rectF2);
        float f = 0.0f;
        switch (o_are.ˏ & 7) {
            case 1:
                f = rectF2.centerX() - rectF.centerX();
                break;
            case 3:
                f = rectF2.left - rectF.left;
                break;
            case 5:
                f = rectF2.right - rectF.right;
                break;
        }
        return f + o_are.ॱ;
    }

    private float ॱ(View view, View view2, are o_are) {
        RectF rectF = this.ˎ;
        RectF rectF2 = this.ˋ;
        ˎ(view, rectF);
        ˎ(view2, rectF2);
        float f = 0.0f;
        switch (o_are.ˏ & 112) {
            case 16:
                f = rectF2.centerY() - rectF.centerY();
                break;
            case 48:
                f = rectF2.top - rectF.top;
                break;
            case 80:
                f = rectF2.bottom - rectF.bottom;
                break;
        }
        return f + o_are.ˊ;
    }

    private void ˎ(View view, RectF rectF) {
        rectF.set(0.0f, 0.0f, (float) view.getWidth(), (float) view.getHeight());
        int[] iArr = this.ˏ;
        view.getLocationInWindow(iArr);
        rectF.offsetTo((float) iArr[0], (float) iArr[1]);
        rectF.offset((float) ((int) (-view.getTranslationX())), (float) ((int) (-view.getTranslationY())));
    }

    private float ˋ(View view, View view2, are o_are) {
        RectF rectF = this.ˎ;
        RectF rectF2 = this.ˋ;
        ˎ(view, rectF);
        ˎ(view2, rectF2);
        rectF2.offset(-ˎ(view, view2, o_are), 0.0f);
        return rectF.centerX() - rectF2.left;
    }

    private float ˊ(View view, View view2, are o_are) {
        RectF rectF = this.ˎ;
        RectF rectF2 = this.ˋ;
        ˎ(view, rectF);
        ˎ(view2, rectF2);
        rectF2.offset(0.0f, -ॱ(view, view2, o_are));
        return rectF.centerY() - rectF2.top;
    }

    private void ˎ(View view, c cVar, aqw o_aqw, aqw o_aqw2, float f, float f2, float f3, float f4, RectF rectF) {
        float ॱ = ॱ(cVar, o_aqw, f, f3);
        float ॱ2 = ॱ(cVar, o_aqw2, f2, f4);
        Rect rect = this.ॱ;
        view.getWindowVisibleDisplayFrame(rect);
        RectF rectF2 = this.ˎ;
        rectF2.set(rect);
        RectF rectF3 = this.ˋ;
        ˎ(view, rectF3);
        rectF3.offset(ॱ, ॱ2);
        rectF3.intersect(rectF2);
        rectF.set(rectF3);
    }

    private float ॱ(c cVar, aqw o_aqw, float f, float f2) {
        long ˋ = o_aqw.ˋ();
        long ˎ = o_aqw.ˎ();
        aqw ˏ = cVar.ˋ.ˏ("expansion");
        return aqv.ˏ(f, f2, o_aqw.ˏ().getInterpolation(((float) (((ˏ.ˎ() + ˏ.ˋ()) + 17) - ˋ)) / ((float) ˎ)));
    }

    @Nullable
    private ViewGroup ˎ(View view) {
        View findViewById = view.findViewById(j.ʻ);
        if (findViewById != null) {
            return ˏ(findViewById);
        }
        if ((view instanceof TransformationChildLayout) || (view instanceof TransformationChildCard)) {
            return ˏ(((ViewGroup) view).getChildAt(0));
        }
        return ˏ(view);
    }

    @Nullable
    private ViewGroup ˏ(View view) {
        if (view instanceof ViewGroup) {
            return (ViewGroup) view;
        }
        return null;
    }

    private int ˊ(View view) {
        ColorStateList ʾ = ViewCompat.ʾ(view);
        if (ʾ != null) {
            return ʾ.getColorForState(view.getDrawableState(), ʾ.getDefaultColor());
        }
        return 0;
    }

    private void ˏ(View view, long j, int i, int i2, float f, List<Animator> list) {
        if (VERSION.SDK_INT >= 21 && j > 0) {
            Animator createCircularReveal = ViewAnimationUtils.createCircularReveal(view, i, i2, f, f);
            createCircularReveal.setStartDelay(0);
            createCircularReveal.setDuration(j);
            list.add(createCircularReveal);
        }
    }

    private void ˎ(View view, long j, long j2, long j3, int i, int i2, float f, List<Animator> list) {
        if (VERSION.SDK_INT >= 21 && j + j2 < j3) {
            Animator createCircularReveal = ViewAnimationUtils.createCircularReveal(view, i, i2, f, f);
            createCircularReveal.setStartDelay(j + j2);
            createCircularReveal.setDuration(j3 - (j + j2));
            list.add(createCircularReveal);
        }
    }
}
